<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Jobs And Such</title></head>

<body>	
<div align="center">
  <p><strong>AMAI Plugins/Job Creation</strong><br>
  <em>Warning this section is an advanced part of AMAI and you need to be fluent in jass </em></p>
  <p align="left">Since version 2.41 it is now possible to make your own code segmants for the ai to follow. This will control the ai in a certain way. Maybe you want to make a script that controls the how players use shops. You can either make your own or edit the already inbuilt ones included.  </p>
  <p align="left">Jobs are basically the equivelent of triggers in warcraft 3 as they run independent of the warcaft script. (In actual fact it only appears to be running independent, of course they are not truly running independent. :D ).This system potentially gives the AMAI engine limitless modability and power. Due to the design of AMAI to simulate triggers, jobs CANNOT USE WAITS/SLEEP commands. Using them could completly mess up the job system. <br>
    <br>
      <strong>Part 1 </strong>-<strong>Creating a Job </strong></p>
  <p align="left">Jobs are found in your job directory of the developer edition. Opening up these in notepad/wordpad shows the code and functions inside. The layout of job coding is as follows. This job is in a file called THIS_JOB.eai </p>
  <div align="left">
    <pre align="left"><em>#IFDEF GLOBAL
 unit u = null
 unit m = null
#ELSE
 function StartJob takes nothing returns nothing
 call DoSomething()</em>
<em> call TQAddJob(10, THIS_JOB, 0)
 endfunction
#ENDIF</em></pre>
  </div>
  <p align="left">The first section you can define global variables. This is for organisation so you can relate variables to a section of code to know where they are used and defined. The second section contains all the core scripts of the job. In this example StartJob function is the entry point where the job starts. You are allowed to create other functions in this section and are not limited to this one. <br>
  <strong>NOTE: </strong>call TQAddJob() is an important part of the job system. This call allows the job to repeat. In this case the job will run again in 50 seconds. If you dont call this command then the job will only run once if its set to start. </p>
  <p align="left"><strong>Part 2 - Linking </strong></p>
  <p align="left">Next you have to link the job into AMAI. Jobs are controlled from a jobs.txt file in your main AMAI directory. It is this file that lists all the different jobs and when they are required to run. The job will not be included into AMAI unless its linked into here. Below is the colums and what they mean. </p>
  <p align="left"><strong>Job ID - </strong>Unique id of job that is supposed to be the same as the Job.eai file it will use<br>
  <strong>Frequency - </strong>This depicts the order to run the jobs. Highest number job is run first before the others are checked. <br>
  <strong>Function Call - </strong>The initial function to be called when job is run (in the example above that would be StartJob()) <br>
  <strong>Condition for initial start time - </strong>If there is a condition to when the job is allowed the start. If true then the job will start only somewhere between the start times otherwise it will not start automatically. You will have to call the job yourself (see part 3 for info) <br>
  <strong>minimum start time - </strong>The smallest amount of time that must pass before starting<br>
  <strong>Maximum start time - </strong>The largest amount of time that can pass before starting</p>
  <p align="left">&nbsp; </p>
  <p align="left"><strong>Part 3 - A</strong><strong>lternative Starts </strong></p>
  <p align="left">If you do not set your job to start  automatically you will have to make it start by placing a command somewhere else in the the amai code. Below are the 3 starting commands for jobs. </p>
  <pre align="left">call TQAddJob(time, Job ID,parameter)
call TQAddUnitJob(time, JOB ID, parameter, unit parameter)
call TQAddGroupJob(time, JOB ID, parameter, unit parameter, group parameter) </pre>
  <p align="left">The parameters allows you to pass an integer, unit or group into the jobs starting function. See below code for an example. </p>
  <pre align="left">function StartingFunctionJob takes group g, unit u, integer p returns nothing </pre>
  <p align="left">You have to decide where you want to put this command, most likely in another job. Placing the command in the common.eai or races.eai is possible too but take care where the command is placed. </p>
</div>
</body>
</html>
